package com.atguigu.tingshu.album.rpc;

import com.atguigu.tingshu.album.mapper.TrackInfoMapper;
import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.vo.album.AlbumListVo;
import com.atguigu.tingshu.vo.album.AlbumStatVo;
import com.atguigu.tingshu.vo.album.TrackInfoVo;
import com.atguigu.tingshu.vo.album.TrackListVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description:
 *
 * @author Yanxinhao on 2025/1/18
 */
@Tag(name = "分类管理")
@RestController
@RequestMapping("/api/album/rpc")
@SuppressWarnings({"unchecked", "rawtypes"})
public class RpcAlbumApiController {

    @Autowired
    private BaseCategoryService baseCategoryService;

    @Autowired
    private AlbumInfoService albumInfoService;
    @Autowired
    private TrackInfoMapper trackInfoMapper;
    @Autowired
    private TrackInfoService trackInfoService;


    /**
     * [rpc]
     * 根据专辑id获取专辑的基本信息以及标签信息
     * @param albumId 专辑id
     * @return 专辑的信息
     */
    @GetMapping("/getAlbumInfo/{albumId}")  // 接收什么方式请求
    @Operation(summary = "根据专辑id获取专辑的基本信息以及标签信息")
    Result<AlbumInfo> getAlumInfo(@PathVariable(value = "albumId") Long albumId) {
        AlbumInfo albumInfo = albumInfoService.getAlbumInfo(albumId);
        return Result.ok(albumInfo);
    }

    /**
     * [rpc]
     * 根据专辑id 获取到分类数据
     * @param albumId 专辑id
     * @return 分类数据
     */
    @GetMapping("/getCategoryView/{albumId}")
    public Result<BaseCategoryView> getCategoryView(@PathVariable(value = "albumId") Long albumId){
        BaseCategoryView view = baseCategoryService.getCategoryView(albumId);
        return Result.ok(view);
    }

    /**
     * [rpc] 根据专辑id获取专辑详情信息【四个维度】
     * @param albumId 专辑id
     * @return 专辑信息
     */
    @GetMapping("/getAlbumStatVoByAlbumId/{albumId}")
    public Result<AlbumStatVo> getAlbumStatVoByAlbumId(@PathVariable(value = "albumId") Long albumId){
        AlbumStatVo vo = albumInfoService.getAlbumStatVoByAlbumId(albumId);
        return Result.ok(vo);
    }

    /**
     * [rpc]
     * 根据一级分类id获取对应的前7个三级分类id对象
     * @param category1Id c1Id
     * @return 前七个三级分类id对象
     */
    @GetMapping("/getTop7Category3ByCategory1Id/{category1Id}")
    public Result<List<BaseCategory3>> getTop7Category3ByCategory1Id(@PathVariable(value = "category1Id") Long category1Id){
        List<BaseCategory3> list = albumInfoService.getTop7Category3ByCategory1Id(category1Id);
        return Result.ok(list);
    }

    /**
     * [rpc]
     * 获取一级分类id集合
     * @return 一级分类id集合
     */
    @GetMapping("/getCategory1IdList")
    public Result<List<Long>> getCategory1IdList(){
        List<Long> list = baseCategoryService.getCategory1IdList();
        return Result.ok(list);
    }

    /**
     * [rpc]
     * 根据音频id集合获取音频信息集合
     * @return 音频信息集合
     */
    @PostMapping("/getTrackInfoListByIds")
    public Result<List<TrackListVo>> getTrackInfoListByIds(@RequestBody List<Long> trackIdList){
        List<TrackListVo> result = trackInfoService.getTrackInfoListByIds(trackIdList);
        return Result.ok(result);
    }

    /**
     * [rpc]
     * 获取所有专辑id集合
     * @return 专辑id集合
     */
    @GetMapping("/getAllAlbumIdList")
    public Result<List<Long>> getAllAlbumIdList(){
        List<Long> list = albumInfoService.getAllAlbumIdList();
        return Result.ok(list);
    }

    /**
     * [rpc]
     * 根据音频id获取音频对象
     * @param trackId 音频id
     * @return 音频对象
     */
    @GetMapping("/getTrackInfoById/{trackId}")
    public Result<TrackInfo> getTrackInfoById(@PathVariable Long trackId){
        TrackInfo trackInfo = albumInfoService.getTrackInfoById(trackId);
        return Result.ok(trackInfo);
    }


    /**
     * [rpc]
     * 获取用户当前可购买的声音列表数据
     * @param userId 用户id
     * @param albumId 专辑id
     * @param trackId 音频id
     * @param trackCount 购买集数
     * @return 可购买音频列表
     */
    @GetMapping("/getCanPaidTrackInfoList/{userId}/{albumId}/{trackId}/{trackCount}")
    Result<List> getCanPaidTrackInfoList(@PathVariable(value = "userId") Long userId,
                                         @PathVariable(value = "albumId") Long albumId,
                                         @PathVariable(value = "trackId") Long trackId,
                                         @PathVariable(value = "trackCount") Integer trackCount){
        return trackInfoService.getCanPaidTrackInfoList(userId,albumId,trackId,trackCount);
    }
}